package com.atguigu.ssyx.product.controller;

import com.atguigu.ssyx.common.result.Result;
import com.atguigu.ssyx.model.product.AttrGroup;
import com.atguigu.ssyx.product.service.AttrGroupService;
import com.atguigu.ssyx.vo.product.AttrGroupQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 杨林
 * @create 2023-07-20 9:27 星期四
 * description:
 */

/**
 * 平台属性分组管理前端总控制器
 */
@Api(tags = "平台属性分组管理")
@RestController
@RequestMapping("/admin/product/attrGroup")
@CrossOrigin  //跨域
public class AttrGroupController {
    
    @Autowired
    private AttrGroupService attrGroupService;

    /**
     * 分页查询平台属性分组列表
     * @return
     */
    @ApiOperation(value = "分页查询平台属性分组列表")
    @GetMapping("/{page}/{limit}")
    public Result getPageList(@PathVariable("page") Long page,
                              @PathVariable("limit") Long limit,
                              AttrGroupQueryVo attrGroupQueryVo){
        IPage<AttrGroup> pageModel = attrGroupService.getPageList(page,limit,attrGroupQueryVo);
        return Result.ok(pageModel);
    }

    /**
     * 根据id获取平台属性分组信息
     * @return
     */
    @ApiOperation(value = "根据id获取平台属性分组信息")
    @GetMapping("/get/{id}")
    public Result getById(@PathVariable("id") Long id){
        AttrGroup attrGroup = attrGroupService.getById(id);
        return Result.ok(attrGroup);
    }

    /**
     * 新增平台属性分组
     * @return
     */
    @ApiOperation(value = "新增平台属性分组")
    @PostMapping("/save")
    public Result save(@RequestBody AttrGroup attrGroup){
        attrGroupService.save(attrGroup);
        return Result.ok();
    }


    /**
     * 根据id更新平台属性分组
     * @return
     */
    @ApiOperation(value = "根据id更新平台属性分组")
    @PutMapping("/update")
    public Result updateById(@RequestBody AttrGroup attrGroup){
        attrGroupService.updateById(attrGroup);
        return Result.ok();
    }

    /**
     * 根据id删除平台属性分组
     * @return
     */
    @ApiOperation(value = "根据id删除平台属性分组")
    @DeleteMapping("/remove/{id}")
    public Result removeById(@PathVariable("id") Long id){
        attrGroupService.removeById(id);
        return Result.ok();
    }

    /**
     * 根据id列表批量删除平台属性分组
     * @return
     */
    @ApiOperation(value = "根据id列表批量删除平台属性分组")
    @DeleteMapping("/batchRemove")
    public Result batchRemove(@RequestBody List<Long> ids){
        attrGroupService.removeByIds(ids);
        return Result.ok();
    }

    /**
     * 查询所有的平台属性分组
     * @return
     */
    @ApiOperation(value = "查询所有的平台属性分组")
    @GetMapping("/findAllList")
    public Result findAllList(){
        List<AttrGroup> result = attrGroupService.findAllList();
        return Result.ok(result);
    }
}
